package cn.itsource.pet.domain;

import cn.itsource.org.domain.TShop;
import cn.itsource.user.WechatConstant;
import cn.itsource.user.domain.TUser;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Id;
import javax.persistence.Transient;

@Data
public class TSearchMasterMessage {
    public static final Integer STATE_XIAJIA = 0;
    public static final Integer STATE_SHANGJIA = 1;

    @Id
    private Long id;
    private String name;
    private Double price;
    private String age;
    private Long gender;
    private String coatColor;
    private String resources;
    private Long petType;
    private String address;
    private Integer state;
    private String title;
    private Long userId;
    private Long shopId;

    @Transient //过滤属性，不参与 表字段的对应关系
    private String resourcesUrls;

    @Transient
    private TUser user;
    @Transient
    private TShop shop;

    //重写getter方法：目的：数据返回到前端时，可以针对列表数据中，每一条数据，某个指定 的属性，进行统一批量修改
    public String getResourcesUrls() {
        if (StringUtils.isNotBlank(this.resources)) {
            //1.先根据 , 拆分保存的图片URL地址
            String[] split = StringUtils.split(this.resources, ",");
            //2. 再将项目中配置的 图片服务器的地址拼接
            for (int i = 0; i < split.length; i++) {
                split[i] = WechatConstant.TRACKER_SERVER + split[i];
            }
            //3.再合并为一个字符串
            //将某一个字符串数组中每个元素按钮  ","拼接为一个字符串
            return StringUtils.join(split, ",");
        }
        return null;
    }

}
